using System;
using System.Windows.Data;

namespace TrackMe.View
{
    public class TimeSpanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string result = null;
            TimeSpan? t = null;
            if (value is TimeSpan)
                t = (TimeSpan)value;

            if (t != null)
            {
            	var dateTime = DateTime.MinValue + t.Value;
            	result = Math.Truncate(t.Value.TotalHours) + dateTime.ToString(":mm:ss");
            }
        	return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
